<template>
    <div>
        <div class="login">
            <el-form ref="form" :model="form" label-width="10vw">
                <el-form-item label="用户名">
                    <el-input v-model="form.name" placeholder="请输入姓名"></el-input>
                </el-form-item>
                <el-form-item label="密码">
                    <el-input v-model.trim="form.password" placeholder="请输入密码" show-password></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button @click="onRegister">注册</el-button>
                    <el-button type="primary" :plain="true" @click="onLogin">登录</el-button>
                </el-form-item>
            </el-form>


        </div>
    </div>
</template>

<script>
export default {
    data(){
        return{
            form:{
                name:'',
                password:'',
            }
        }
    },
    methods: {
        onLogin(){
            // 当点击登录按钮时，触发actions中的login_a
            this.$store.dispatch("login_a",{
                user_name:this.form.name,
                password:this.form.password,
                // 将$router传递给actions中的login_a
                routerT:this.$router
            })
            
        },
        onRegister(){
            // 点击注册按钮，跳转到注册页面
            this.$router.push({
                path:'/register'
            })
        }
    }

}
</script>

<style lang="scss" scoped>
div {
    width: 100%;
    height: 100%;
    background: url("~@/assets/images/01.webp") no-repeat center center;
    background-size: cover;
    display: flex;
    align-items: center;
    justify-content: center;

    .login {
        width: 400px;
        height: 200px;
        border-radius: 20px;
        box-shadow: 0 0 10px 10px #CFD8F7;
        background: url("~@/assets/images/01.webp") no-repeat center center;
        background-size: cover;
        opacity: 0.6;

        h2 {
            color: white;
        }
    }
}
</style>